package cn.yunhe.controller;

import cn.yunhe.entity.Reply;
import cn.yunhe.service.IreplyService;
import cn.yunhe.service.implService.ReplyService;
import cn.yunhe.util.JsonUtil;
import cn.yunhe.util.Paganation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "GetALLReplyServlet",urlPatterns = "/GetALLReplyServlet")
public class GetALLReplyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageNoStr=request.getParameter("pageNo");
        int pageNo=1;
        if(pageNoStr!=null){
            pageNo=Integer.parseInt(pageNoStr);
        }//确定当前页

        Paganation<Reply> paganation=new Paganation<Reply>();

        Paganation paganation1=new Paganation();//把查询tb_reply需要的Paganation对象准备好
        paganation1.setPageNo(pageNo);
        Reply reply=new Reply();//准备查询tb_reply所需要的Reply对象(使用对象的原因,方法以后扩展)

        IreplyService ireplyService=new ReplyService();
        paganation=ireplyService.getAllReply(reply,paganation1);

        JsonUtil.getJson(response,paganation);//把paganation 对象通过Json 格式发到前台
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }
}
